package com.vp.org.web.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebFilter(filterName = "filter", urlPatterns = {"/user/index.jsp",
        "/user/details.jsp", "/user/buy.jsp", "/user/center/*"})
public class SessionFilter implements Filter {

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) resp;

        if (request.getSession().getAttribute("user") != null)
            chain.doFilter(req, resp);
        else response.sendRedirect("/user/login.jsp?msg=0");
    }

}
